package service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import dao.ApplyMapper;
import dao.ApplyoutMapper;
import dao.CheckoutMapper;
import dao.HouselistMapper;
import dao.PaidMapper;
import dao.SolveMapper;
import dao.TopaidMapper;
import dao.UserMapper;
import dao.UserlistMapper;
import dao.WrongMapper;
import dao.ZulistMapper;
import pojo.User;
import pojo.Userlist;

@Service
@Transactional
public class UserlistServiceImpl implements UserlistService {

	@Autowired
	private UserlistMapper userlistMapper;

	@Autowired
	private UserMapper userMapper;

	@Autowired
	private ApplyMapper applyMapper;

	@Autowired
	private ApplyoutMapper applyoutMapper;

	@Autowired
	private CheckoutMapper checkoutMapper;

	@Autowired
	private HouselistMapper houselistMapper;

	@Autowired
	private PaidMapper paidMapper;

	@Autowired
	private SolveMapper solveMapper;

	@Autowired
	private TopaidMapper topaidMapper;

	@Autowired
	private WrongMapper wrongMapper;

	@Autowired
	private ZulistMapper zulistMapper;

	@Override
	public Userlist findhasuserlist(Integer user_id) {
		Userlist userlist = userlistMapper.findhasuserlist(user_id);
		return userlist;
	}

	@Override
	public Userlist checkuserlist(String idcard) {
		Userlist userlist = userlistMapper.checkuserlist(idcard);
		return userlist;
	}

	@Override
	public void insertuserlist(Userlist userlist) {
		userlistMapper.insertuserlist(userlist);

	}

	@Override
	public void updateuserlist(Userlist userlist) {
		userlistMapper.updateuserlist(userlist);

	}

	@Override
	public Userlist finduserlistupdate(Userlist userlist) {
		Userlist list = userlistMapper.finduserlistupdate(userlist);
		return list;
	}

	@Override
	public List<Userlist> getUserzuList(Integer id) {
		List<Userlist> userlist = userlistMapper.getUserzuList(id);
		for (Userlist list : userlist) {
			System.out.println(list);
		}
		return userlist;
	}

	@Override
	public List<Userlist> getmycheckout(Integer id) {
		List<Userlist> list = userlistMapper.getmycheckout(id);
		return list;
	}

	@Override
	public List<Userlist> getmyapply(Integer id) {
		List<Userlist> list = userlistMapper.getmyapply(id);
		return list;
	}

	@Override
	public List<Userlist> getmyapplyout(Integer id) {
		List<Userlist> list = userlistMapper.getmyapplyout(id);
		return list;
	}

	@Override
	public List<Userlist> findalluserlist() {
		List<Userlist> list = userlistMapper.findalluserlist();
		return list;
	}

	@Override
	public void deleteuserlist(Integer id) {
		Userlist userlist = userlistMapper.findid(id.toString());
		applyMapper.deletebyuserlistid(id);
		applyoutMapper.deletebyuserlistid(id);
		checkoutMapper.deletebyuserlistid(id);
		houselistMapper.deletebyuserlistid(userlist.getUser().getId());
		paidMapper.deletebyuserlistid(id);
		solveMapper.deletebyuserlistid(id);
		topaidMapper.deletebyuserlistid(id);
		wrongMapper.deletebyuserlistid(id);
		zulistMapper.deletebyuserlistid(id);
		userlistMapper.deleteuserlist(id);
		userlistMapper.deleteuser(id);
	}

	@Override
	public void updateuser(Userlist userlist, String username, Integer userid) {
		userlistMapper.updateuserlist(userlist);
		User user = userMapper.selectByPrimaryKey(userid);
		userlistMapper.updateuser(user);
	}

}
